<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改设备D端口')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-cargo-edit" th:object="${bizDeviceCargo}">
            <input name="id" th:field="*{id}" type="hidden">
            <input id="goodsCostPrice" name="goodsCostPrice"  type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">端口编号：</label>
                <div class="col-sm-8">
                    <input name="number" th:field="*{number}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">电名称：</label>
                <div class="col-sm-8">
                    <select id="goodsId" name="goodsId" onchange="setPrice()" class="form-control m-b" th:with="type=${@udwl.getTableData('biz_goods','id','name','enable')}">
                        <option value="0">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{goodsId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">电售价(KWH/元)：</label>
                <div class="col-sm-8">
                    <input  id="goodsPrice" name="goodsPrice" th:field="*{goodsPrice}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">折扣(%)：</label>
                <div class="col-sm-8">
                    <input name="goodsDiscount" th:field="*{goodsDiscount}" class="form-control" type="text" required>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "biz/cargo";
        $("#form-cargo-edit").validate({
            focusCleanup: true
        });

        /**
         * 带出原来电价格
         * @param goodsId
         */
        function setPrice(){
            var goodsId = $("#goodsId").val();
            $.get(ctx + "biz/goods/get/"+goodsId,function (res){
                $("#goodsPrice").val(res.price);
                $("#goodsCostPrice").val(res.costPrice);
            });
        }
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-cargo-edit').serialize());
            }
        }
    </script>
</body>
</html>